package dao;

import model.tickets;
import util.ConnMySQL;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class TicketDao {
    public static String getidtickets(String goPlace,String arrivePlace,String leaveTime) throws Exception {
        String id = null;
        try {

            Connection conn = ConnMySQL.getConnection();
            PreparedStatement ps = (PreparedStatement) conn
                    .prepareStatement("select number from tickets where  goPlace =? and arrivePlace = ? and leaveTime=?");
            // ps.setString(1, "name");
            ps.setString(1, goPlace);
            ps.setString(2,arrivePlace);
            ps.setString(3,leaveTime);
            ResultSet rs = ps.executeQuery();
            // List<Student> list = new ArrayList();
            while (rs.next()) {
                id = rs.getString("number");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return id;
    }

    public static String getleaveTime(String goPlace,String arrivePlace,String leaveTime) throws Exception {
        String LeaveTime = null;
        try {
            Connection conn = ConnMySQL.getConnection();
            PreparedStatement ps = (PreparedStatement) conn
                    .prepareStatement("select leaveTime from tickets where  goPlace =? and arrivePlace = ? and leaveTime=?");
            // ps.setString(1, "name");
            ps.setString(1, goPlace);
            ps.setString(2,arrivePlace);
            ps.setString(3,leaveTime);
            ResultSet rs = ps.executeQuery();
            // List<Student> list = new ArrayList();
            while (rs.next()) {
                LeaveTime = rs.getString("leaveTime");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return leaveTime;
    }

    public static String getgoTime(String goPlace,String arrivePlace,String leaveTime) throws Exception {
        String  goTime = null;
        try {
            Connection conn = ConnMySQL.getConnection();
            PreparedStatement ps = (PreparedStatement) conn
                    .prepareStatement("select goTime from tickets where  goPlace =? and arrivePlace = ? and leaveTime=?");
            // ps.setString(1, "name");
            ps.setString(1, goPlace);
            ps.setString(2,arrivePlace);
            ps.setString(3,leaveTime);
            ResultSet rs = ps.executeQuery();
            // List<Student> list = new ArrayList();
            while (rs.next()) {
                goTime = rs.getString("goTime");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return goTime;
    }

    public static String getarriveTime(String goPlace,String arrivePlace,String leaveTime) throws Exception {
        String  arriveTime = null;
        try {
            Connection conn = ConnMySQL.getConnection();
            PreparedStatement ps = (PreparedStatement) conn
                    .prepareStatement("select arriveTime from tickets where  goPlace =? and arrivePlace = ? and leaveTime=?");
            // ps.setString(1, "name");
            ps.setString(1, goPlace);
            ps.setString(2,arrivePlace);
            ps.setString(3,leaveTime);
            ResultSet rs = ps.executeQuery();
            // List<Student> list = new ArrayList();
            while (rs.next()) {
                arriveTime = rs.getString("arriveTime");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return arriveTime;
    }
}
